package com.bw.module_home.ui.marketers

import androidx.activity.viewModels
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.lib_common.arouter.Router
import com.bw.lib_common.base.BaseActivity
import com.bw.module_home.R
import com.bw.module_home.databinding.ActivityBusinessProfileAddBinding
import com.bw.module_home.marketer.model.BusinessProfileEntity
import com.bw.module_home.marketer.model.BusinessProfileEntityItem
import com.bw.module_home.marketer.viewmodel.MarketersViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/module_marketers/businessProfileAddActivity")
class BusinessProfileAddActivity : BaseActivity<MarketersViewModel, ActivityBusinessProfileAddBinding>() {
    private val viewModel: MarketersViewModel by viewModels()

    override val mLayoutResId: Int
        get() = R.layout.activity_business_profile_add

    override fun initView() {
        super.initView()
        mBinding.ivBack.setOnClickListener {
            finish()
        }
        mBinding.btnSubmit.setOnClickListener {
//            val businessProfileEntity = BusinessProfileEntity()
            val item = BusinessProfileEntityItem(
                address = mBinding.etAddress.text.toString(),
                contactInfo = mBinding.etContactInfo.text.toString(),
                id = 0,
                industryType = mBinding.etIndustryType.text.toString(),
                legalRepresentative = mBinding.etLegalRepresentative.text.toString(),
                listed = mBinding.swListed.isChecked,
                name = mBinding.etBusinessName.text.toString(),
                photos = listOf("http://example.com/photo1.jpg", "http://example.com/photo2.jpg"),
                status = mBinding.etStatus.text.toString(),
                stockCode = mBinding.etStockCode.text.toString(),
                stockName = mBinding.etStockName.text.toString()
            )
//            businessProfileEntity.add(item)
//            viewModel.addBusinessProfile(businessProfileEntity)
            viewModel.addBusinessProfile(item)
        }
    }

    override fun initListener() {
        super.initListener()
        viewModel.addBusinessProfile.observe(this) {
            showToast("添加成功")
            ARouter.getInstance().build(Router.Ui.MarketersActivity).navigation()
        }
        viewModel.mErrorLiveData.observe(this) {
            showToast(it)
        }
    }
}